#ifndef __MINIKIT_STRING_H__
#define __MINIKIT_STRING_H__
#include <string>
#include <vector>
#include <map>
#include <stdint.h>
#include <stdarg.h>

#define __from_string(s_from, to, ss) \
do{\
	ss.clear();\
	ss.str(s_from);\
	ss>>to;\
}while(0)

#define __to_string(from, s_to, ss) \
do{\
	ss.clear();\
	ss.str("");\
	ss<<from;\
	s_to = ss.str();\
}while(0)

namespace MINIKIT
{

class Text
{
public:
	static char          c2x( unsigned char c );
	static unsigned char x2c( const char *what );

	static void   upper( char* sz );
	static void   upper( std::string &s );
	static void   lower( char* sz );
	static void   lower( std::string &s );
	static size_t split( const std::string &s, const std::string &sep, std::vector<std::string> &out_result);
	static size_t replace( std::string& src, const char* token, const char* symbol);

	static std::string trimL( std::string &str, char c='\0');
	static std::string trimR( std::string &str, char c='\0');
	static std::string trim( std::string &str,  char c='\0');

	static void    conv_gbk_utf8( std::string &s );
	static void    conv_utf8_gbk( std::string &s );
	static int32_t conv( const char *szCharsetFrom, const char *szCharsetTo, char *szIn, size_t lenIn, char *szOut, size_t lenOut);

	static void    escape( const std::string &s, std::string &s_out );
	static int32_t escape( const char *pszStr, char * pszResult, uint32_t iOutLen );

	static void    unescape( const std::string &s, std::string &s_out );
	static void    unescape( char* sz );

	static size_t  sprintf( std::string& s_out, const char* fmt, ... );
	//uint32_t getVarLength(const char* fmt, va_list args);
};//class Text

class Http
{
public:
	static uint32_t ParseHeader( const std::string &header_string, std::map<std::string, std::string>& out_fields, const std::string &namelist="" );
	static uint32_t ParseQueryString( const std::string &query_string, std::map<std::string, std::string>& out_params, const std::string &namelist="" );
	static uint32_t ParseCookie( const std::string& cookie_string, std::map<std::string, std::string>& out_cookies, const std::string &namelist="" );

};//class Http


}; //namespace MINIKIT

#endif /*__MINIKIT_STRING_H__*/

